package com.zb.service.impl;

import com.zb.entity.ZjWorkSet;
import com.zb.service.WorkRepeatService;
import com.zb.service.ZjWorkOrderService;
import com.zb.service.ZjWorkSetService;
import com.zb.vo.WorkRepeatSearchVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author WEN
 * @Date 2024/4/24 0024
 **/
@Service
public class WorkRepeatServiceImpl implements WorkRepeatService {
    @Resource
    private ZjWorkSetService workSetService;
    @Resource
    private ZjWorkOrderService workOrderService;

    // 获取重复工单配置
    @Override
    public Object getWorkRepeatConfig(Long custAccId, WorkRepeatSearchVo search) {
        ZjWorkSet workSet = workSetService.getById(custAccId);
        if (!workSet.getEnableUserAccount()) search.setUserAccount(null);
        if (!workSet.getEnableUserName()) search.setUsername(null);
        if (!workSet.getEnableUserPhone()) search.setUserPhone(null);
        if (!workSet.getEnableUserAddress()){
            search.setUserProvince(null);
            search.setUserCity(null);
            search.setUserArea(null);
            search.setUserTown(null);
            search.setUserAddress(null);
        }
        if (!workSet.getEnableProName()) search.setGoodsName(null);
        if (!workSet.getEnableProModel()) search.setGoodsModel(null);
        if (!workSet.getEnableProCode()) search.setCode(null);
        List<Long> workIds = workOrderService.getWorkRepeat(custAccId, search);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("enableRepeatOrder", workSet.getEnableRepeatOrder() && workSet.getRepeatByService()); // 是否允许重复报单
        resultMap.put("enableRepeatOrderTip", workSet.getEnableRepeatOrder() && workSet.getRepeatByServiceTip()); // 是否启用重复报单提示
        resultMap.put("count", workIds.size());
        resultMap.put("workIds", workIds);
        return resultMap;
    }




}
